var shop = {
		
		search:function(){
			/*  滚动条  */
			var width = $('.brand-scroll li').size()*(0.714*parseInt($("html").css('fontSize')));
			$('.brand-scroll li').each(function(){
				width += parseInt($(this).width());
			})
			$('.brand-scroll ul').width(width);
			/*  下拉列表  */
			if($('.brand-mose').size()>0){
				$('.brand-choice').on('click','.brand-mose',function(event){
					$(this).toggleClass('sion-show');
					$('.am-dimmer').toggleClass('am-block');
					event.stopPropagation();
				});
				$('.am-dimmer').click(function(event){
					$('.brand-mose').toggleClass('sion-show');
					$('.am-dimmer').toggleClass('am-block');
					event.stopPropagation();
				});
			}
			/*  搜索  */
			$('.brand-head').on('click','.search-input',function(event){
				$('.page-1').addClass('am-hide');
				$('.page-2').removeClass('am-hide');
				$('.brand-mose').removeClass('sion-show');
				$('.am-dimmer').removeClass('am-block');
				$('.boost-input input').focus();
				event.stopPropagation();
			});
			$('.boost-head').on('click','.boost-colse',function(event){
				$('.page-1').removeClass('am-hide');
				$('.page-2').addClass('am-hide');
				event.stopPropagation();
			});
			$('.boost-pull').on('click','.boost-content li',function(event){
				$(this).addClass('active').siblings().removeClass('active');
				$('.boost-pull').dropdown('close');
				$('.boost-shop').text($(this).text());
				event.stopPropagation();
			});
			$('.brand-choice').on('click','li a',function(e){
		        $(this).parent().addClass('active').siblings().removeClass('active');
		        $('.brand-mose').removeClass('sion-show');
		        $('.am-dimmer').removeClass('am-block');
		        var href = $(this).attr('href');
		        $.ajax({
		            type : 'get',
		            dataType : 'json',
		            async : false,
		            url : href,
		            beforeSend:function(){
		            	$('.brand-list .load-logo').show();
		    	    	$('.no-more').addClass('am-hide');
		    	    	$('#my-scrollspy').addClass('am-hide');
		       	    },
		            success : function (data){
		                if (data.status) {
		                    $('.shop-list').html(data.html);
		                    if(data.num >= 13){
		                    	$('#my-scrollspy').removeClass('am-hide').attr('pg',data.pg).show();
		                    }
		                }  else {
		                	 $('.shop-list').html('<li class="no_result flex flex-align-center">'+
		                			 '<div class="no_center"><img src="images/no_result.png" />' +
		                			 '<p>木有结果，再找找看！</p></div></li>');
		                } 
		                $('.brand-list .load-logo').hide();
		                $('img.lazy').lazyload();
		            }
		        });
		        e.preventDefault();
		        return false;
		    });
			$('.sion-list').on('click','.clear-cookie',function(){
				if(confirm('确定删除吗')){
					$.ajax({
	                      type : 'post',
	                      url  : hostUrl()+'shop/ajaxClearCookie',
	                      dataType:'json',
	                      success:function(data){
	                           if(data.status){
	                                $('.boost-sion .history-search').remove();
	                           }
	                      }
					})
				}
			});
			
		},
		pageTurning:function(){
			$('#my-scrollspy').scrollspy({
                animation: 'fade',
                delay: 500
	        });
			$('#my-scrollspy').on('inview.scrollspy.amui', function() {
				 var pg = parseInt($('.sec-load').attr('pg'))+1;
				 $.ajax({
	                    type: 'GET',
	                    dataType: 'json',
	                    data:{pg:pg},
	                    url: hostUrl()+'shop/ajaxShop?'+location.search,
	                    success: function(data) {
	                        if (data.status) {
	                            $('.brand-list .shop-list').append(data.html);
	                            $('.sec-load').attr('pg',data.pg);
	                        } else {
	                            $('#my-scrollspy').hide();
	                            $('.no-more').removeClass('am-hide');
	                        }
	                        $('img.lazy').lazyload();
	                    },
	                    error : function(jqXHR){
	                        console.log(jqXHR.status);
	                    }
	                });
			})
		},
		initial:function(){
			shop.search();
			shop.pageTurning();
		}
}
jQuery(function(){
	
	shop.initial();
})